USE SAS
GO

IF EXISTS (SELECT 1 from sysobjects where xtype = 'FN' AND NAME = 'GetRefSourcesXml')
	DROP FUNCTION dbo.GetRefSourcesXml
GO


CREATE FUNCTION [dbo].[GetRefSourcesXml] ()
RETURNS VARCHAR(MAX)
AS
BEGIN
	
	declare 
		@xml			varchar(max)

	SET @xml	= '<REFSOURCES><entry id=""></entry>'

	select @xml = @xml + '<entry id="' + CAST(DataOrigin AS VARCHAR) + '"><![CDATA[' +  OriginDesc + ']]></entry>'
	FROM TR_DATAORIGIN order by OriginDesc
	set @xml = @xml + '</REFSOURCES>'


	return @xml

END
